/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import dominio.Asignatura;
import dominio.Seccion;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import negocio.AsignaturaNegocio;
import negocio.SeccionNegocios;
import utilidades.JFondo;
import utilidades.Validaciones;
//import utilidades.PopupEspecialidades;

/**
 *
 * @author Richard
 */
public class JIF_Seccion extends javax.swing.JInternalFrame {

    private SeccionNegocios SeccionNegocios;

//    private PopupEspecialidades popupEspecialidades;

    public JIF_Seccion() throws SQLException {
        initComponents();
        SeccionNegocios=new SeccionNegocios();
        ocultarPanelSubareas();
        JP_asignaturaGeneral.setBorder(new JFondo("../imagenes/fondo_2.jpg"));
    }

//    private void llenarTablaEspecialidades() throws SQLException {
//        asignaturaNegocio = new AsignaturaNegocio();
//        String siglaSeleccionada = JT_asignaturasTecnicas.getValueAt(JT_asignaturasTecnicas.getSelectedRow(), 0).toString();
//        JT_especialidadesDeSubarea.setModel(asignaturaNegocio.getEspecialidadesDeSubarea(siglaSeleccionada));
//        if (JT_especialidadesDeSubarea.getRowCount() > 0) {
//            JT_especialidadesDeSubarea.getColumn("idEspecialidad").setPreferredWidth(0);
//            JT_especialidadesDeSubarea.getColumn("idEspecialidad").setMinWidth(0);
//            JT_especialidadesDeSubarea.getColumn("idEspecialidad").setWidth(0);
//            JT_especialidadesDeSubarea.getColumn("idEspecialidad").setMaxWidth(0); 
//        }
//    }//Fin llenarTablas()
    private void ocultarPanelSubareas() {
//        JSP_nivel.setValue(7);
//        try {
//	            DefaultTableModel modelo=(DefaultTableModel) JT_especialidadesDeSubarea.getModel();
//	            int filas=JT_especialidadesDeSubarea.getRowCount();
//	            for (int i = 0;filas>i; i++) {
//	                modelo.removeRow(0);
//	            }
//	        } catch (Exception e) {}
        JP_especialidadesLigadasSubarea.setVisible(false);
    }


    private void limiparEspacios() {  
        JTF_siglaSeccion.setText("");
        JTF_cantidadEstud.setText("");

    }



    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JP_asignaturaGeneral = new javax.swing.JPanel();
        JP_datosGeneralesAsignatura = new javax.swing.JPanel();
        JP_especialidadesLigadasSubarea = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        JTF_siglaSeccion = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        JTF_cantidadEstud = new javax.swing.JTextField();
        JP_botoneraAceptCancel = new javax.swing.JPanel();
        JB_insertar = new javax.swing.JButton();
        JB_cancelar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        JMB_barraAsignaturas = new javax.swing.JMenuBar();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Mantenimiento de asignatura");
        setMaximumSize(new java.awt.Dimension(1000, 550));
        setMinimumSize(new java.awt.Dimension(100, 60));
        setPreferredSize(new java.awt.Dimension(1000, 550));
        getContentPane().setLayout(null);

        JP_asignaturaGeneral.setPreferredSize(new java.awt.Dimension(1000, 520));

        JP_datosGeneralesAsignatura.setBackground(new java.awt.Color(255, 255, 255));
        JP_datosGeneralesAsignatura.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        JP_datosGeneralesAsignatura.setPreferredSize(new java.awt.Dimension(502, 410));

        JP_especialidadesLigadasSubarea.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout JP_especialidadesLigadasSubareaLayout = new javax.swing.GroupLayout(JP_especialidadesLigadasSubarea);
        JP_especialidadesLigadasSubarea.setLayout(JP_especialidadesLigadasSubareaLayout);
        JP_especialidadesLigadasSubareaLayout.setHorizontalGroup(
            JP_especialidadesLigadasSubareaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 480, Short.MAX_VALUE)
        );
        JP_especialidadesLigadasSubareaLayout.setVerticalGroup(
            JP_especialidadesLigadasSubareaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 52, Short.MAX_VALUE)
        );

        jLabel1.setText("Sigla: ");

        jLabel2.setText("Cantidad de Estudiantes");

        JP_botoneraAceptCancel.setBackground(new java.awt.Color(255, 255, 255));

        JB_insertar.setText("Registrar");
        JB_insertar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_insertarActionPerformed(evt);
            }
        });

        JB_cancelar.setText("Cancelar");
        JB_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_cancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JP_botoneraAceptCancelLayout = new javax.swing.GroupLayout(JP_botoneraAceptCancel);
        JP_botoneraAceptCancel.setLayout(JP_botoneraAceptCancelLayout);
        JP_botoneraAceptCancelLayout.setHorizontalGroup(
            JP_botoneraAceptCancelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_botoneraAceptCancelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(JB_cancelar)
                .addGap(18, 18, 18)
                .addComponent(JB_insertar)
                .addContainerGap())
        );
        JP_botoneraAceptCancelLayout.setVerticalGroup(
            JP_botoneraAceptCancelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_botoneraAceptCancelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JP_botoneraAceptCancelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JB_insertar)
                    .addComponent(JB_cancelar))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jLabel5.setText("Registrar Seccion");

        javax.swing.GroupLayout JP_datosGeneralesAsignaturaLayout = new javax.swing.GroupLayout(JP_datosGeneralesAsignatura);
        JP_datosGeneralesAsignatura.setLayout(JP_datosGeneralesAsignaturaLayout);
        JP_datosGeneralesAsignaturaLayout.setHorizontalGroup(
            JP_datosGeneralesAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_datosGeneralesAsignaturaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JP_especialidadesLigadasSubarea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JP_datosGeneralesAsignaturaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(JP_botoneraAceptCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
            .addGroup(JP_datosGeneralesAsignaturaLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(JP_datosGeneralesAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(JP_datosGeneralesAsignaturaLayout.createSequentialGroup()
                        .addGroup(JP_datosGeneralesAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(72, 72, 72)
                        .addGroup(JP_datosGeneralesAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(JTF_cantidadEstud)
                            .addComponent(JTF_siglaSeccion, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        JP_datosGeneralesAsignaturaLayout.setVerticalGroup(
            JP_datosGeneralesAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_datosGeneralesAsignaturaLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel5)
                .addGap(67, 67, 67)
                .addGroup(JP_datosGeneralesAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(JTF_siglaSeccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(72, 72, 72)
                .addGroup(JP_datosGeneralesAsignaturaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(JTF_cantidadEstud, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JP_especialidadesLigadasSubarea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                .addComponent(JP_botoneraAceptCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout JP_asignaturaGeneralLayout = new javax.swing.GroupLayout(JP_asignaturaGeneral);
        JP_asignaturaGeneral.setLayout(JP_asignaturaGeneralLayout);
        JP_asignaturaGeneralLayout.setHorizontalGroup(
            JP_asignaturaGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_asignaturaGeneralLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(JP_datosGeneralesAsignatura, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(482, Short.MAX_VALUE))
        );
        JP_asignaturaGeneralLayout.setVerticalGroup(
            JP_asignaturaGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_asignaturaGeneralLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JP_datosGeneralesAsignatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(69, Short.MAX_VALUE))
        );

        getContentPane().add(JP_asignaturaGeneral);
        JP_asignaturaGeneral.setBounds(0, 0, 1000, 490);
        setJMenuBar(JMB_barraAsignaturas);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JB_insertarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_insertarActionPerformed
 
        boolean insertado=false;
        
         if(JTF_siglaSeccion.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Debe insertar el nombre de la seccion");}
         else if(JTF_cantidadEstud.getText().equals("")){
            JOptionPane.showMessageDialog(null, "Debe insertar el numero de estudiantes");
    }else{
       Seccion seccionAInsertar=new Seccion();
       seccionAInsertar.setIdentificadorSeccion(JTF_siglaSeccion.getText());
       seccionAInsertar.setCantidadEstudiantes(Integer.parseInt(JTF_cantidadEstud.getText()));
        try {
            insertado=SeccionNegocios.insertarSeccion(seccionAInsertar);
        } catch (SQLException ex) {
            Logger.getLogger(JIF_Seccion.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(insertado)
            JOptionPane.showMessageDialog(null, "seccion registrada");
        else{
        JOptionPane.showMessageDialog(null, "error, seccion no registrada");
        }
         }
        
    }//GEN-LAST:event_JB_insertarActionPerformed

    private void JB_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_cancelarActionPerformed

    }//GEN-LAST:event_JB_cancelarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JB_cancelar;
    private javax.swing.JButton JB_insertar;
    private javax.swing.JMenuBar JMB_barraAsignaturas;
    private javax.swing.JPanel JP_asignaturaGeneral;
    private javax.swing.JPanel JP_botoneraAceptCancel;
    private javax.swing.JPanel JP_datosGeneralesAsignatura;
    private javax.swing.JPanel JP_especialidadesLigadasSubarea;
    private javax.swing.JTextField JTF_cantidadEstud;
    private javax.swing.JTextField JTF_siglaSeccion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    // End of variables declaration//GEN-END:variables
}
